<template>
    <div>
      userId：<input type="text" v-model="userId" style="border: 1px solid #ccc; border-radius: 5px; padding: 5px; margin-bottom: 10px;"/><br>
      roleId：<input type="text" v-model="roleId" style="border: 1px solid #ccc; border-radius: 5px; padding: 5px; margin-bottom: 10px;"/><br>
      <button @click="login" style="border: 1px solid #ccc; border-radius: 5px; padding: 5px; margin-bottom: 10px;">登录</button>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import { generateJWT } from '@/utils/generateToken'
import { useServerUserStore } from '@/stores/modules/user-server'
import { useRouter } from 'vue-router'  

const userId = ref('')
const roleId = ref('')
const router = useRouter()
const userStore = useServerUserStore()

const login = async () => {
  const token = await generateJWT(userId.value, roleId.value)
  console.log('token: ',token)
  userStore.setToken(token)
  userStore.setUserInfo(parseInt(userId.value), parseInt(roleId.value))
  router.push('/')
}
</script>

<style scoped>

</style>
